﻿/* Copyright (c)
* 
*Create by BTDat
*Date:2013/12/13
*
*/
var HH_mm_ss = '00:00:00';
var HH_mm_tt = "12:00 AM";
var controller = 'WorkReport';
//============================================================================================//

//-----------------------------------//
//  OnDateChanged()
// For StartTime And FinishTime
//-----------------------------------//

function OnDateChanged() {
    //Xu ly
    //1. Get Id of model
    var _Id = $('#Id').val();
    var startValue = $('#StartTime').val();
    var finishValue = $('#FinishTime').val();
    var _Start = parseTimeSpan(startValue);
    var _Finish = parseTimeSpan(finishValue);
    //Get NextDay
    var _NextDay = $('#NextDay').prop('checked'); //ouput: true||false

    //_____________________________________________________________________

    var date = $('#Date').val();
    var dtStart = new Date(new Date().toDateString() + " " + startValue);
    var dtFinish = new Date(new Date().toDateString() + " " + finishValue)
    //__Add 1 day if NextDay="true"
    var temp = false;
    if (_NextDay == true) {
        dtFinish.setDate(dtFinish.getDate() + 1);
        //Check if Gio ra> NightTimeTo
        $.ajax({
            url: '/' + controller + '/CompareFinishAndLateNightTime?finishdatetime=' + _Finish,
            type: "GET",
            dataType: 'json',
            contentType: 'application/json;',
            data: JSON.stringify({ finishdatetime: _Finish }),
            success: function (jsonData) {
                if (jsonData != null) {
                    if (jsonData.error = "1" || (_Start == HH_mm_ss && _Finish == HH_mm_ss)) {
                        alert("Finish cannot be greater than " + jsonData.ruleNightTimeTo + ".");
                        //ShowDialogBox("Finish cannot be greater than " + jsonData.ruleNightTimeTo + ".", 'OK', DefaultCallBack);
                        //Set focus on Finish
                        $('#FinishTime').focus();
                        temp = true;
                    }
                }
            }
        });
       if (temp) return;
   }
   
   // Start cannot be greater than finish 
   if (dtStart > dtFinish && _Finish != HH_mm_ss) {
       alert('Start cannot be greater than Finish.');
       //ShowDialogBox('Start cannot be greater than Finish.', 'OK', DefaultCallBack);
        //Set default value and focus on field
        return;
    }
    //_________________________________________________________________________________________
    $.ajax({
        url: '/' + controller + '/CalculatingOT?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
        type: "GET",
        dataType: 'json',
        contentType: 'application/json;',
        data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish, isnextday: _NextDay }),
        success: function (jsonData) {
            if (jsonData != null) {
                if (jsonData.CalendarType == "1") {
                    //Set gia tri cho Fields

                    $('#OTBeforeAfter').val(jsonData.OTBeforeAfter);
                    $('#OTLateNight').val(jsonData.OTLateNight);

                    $('#WeekendShift').val(0);
                    $('#WeekendOT').val(0);
                    $('#WeekendOTNight').val(0);

                    $('#NaHolidayShift').val(0);
                    $('#NaHolidayOT').val(0);
                    $('#NaHolidayOTNight').val(0);
                }
                else if (jsonData.CalendarType == "3") {
                    //Set gia tri cho Fields
                    $('#OTBeforeAfter').val(0);
                    $('#OTLateNight').val(0);

                    $('#WeekendShift').val(jsonData.OTShift);
                    $('#WeekendOT').val(jsonData.OTBeforeAfter);
                    $('#WeekendOTNight').val(jsonData.OTLateNight);

                    $('#NaHolidayShift').val(0);
                    $('#NaHolidayOT').val(0);
                    $('#NaHolidayOTNight').val(0);
                }
                else if (jsonData.CalendarType == "2" || jsonData.CalendarType == "4") {

                    //Set gia tri cho Fields
                    $('#OTBeforeAfter').val(0);
                    $('#OTLateNight').val(0);

                    $('#WeekendShift').val(0);
                    $('#WeekendOT').val(0);
                    $('#WeekendOTNight').val(0);

                    $('#NaHolidayShift').val(jsonData.OTShift);
                    $('#NaHolidayOT').val(jsonData.OTBeforeAfter);
                    $('#NaHolidayOTNight').val(jsonData.OTLateNight);

                }
                if (jsonData.IsNextDay == "1") {
                    var OTLateNightNextDay = parseFloatCustom(jsonData.OTLateNightNextDay);
                    var OTLateNight = parseFloatCustom(jsonData.OTLateNight)

                    if (jsonData.CalendarTypeOfNextDay == "1") {
                        if (jsonData.CalendarType == "1") {
                            $('#OTLateNight').val(OTLateNight + OTLateNightNextDay);
                            //dxGrid.SetEditValue('OTLateNight', OTLateNight + OTLateNightNextDay);
                        }
                        else if (jsonData.CalendarType == "3") {
                            $('#OTLateNight').val(jsonData.OTLateNightNextDay);
                            //dxGrid.SetEditValue('OTLateNight', jsonData.OTLateNightNextDay);
                        }
                        else if (jsonData.CalendarType == "2" || jsonData.CalendarType == "4") {
                            $('#OTLateNight').val(jsonData.OTLateNightNextDay);
                        }

                    }
                    else if (jsonData.CalendarTypeOfNextDay == "3") {
                        if (jsonData.CalendarType == "1") {
                            $('#WeekendOTNight').val(jsonData.OTLateNightNextDay);
                            //dxGrid.SetEditValue('WeekendOTNight', jsonData.OTLateNightNextDay);
                        }
                        else if (jsonData.CalendarType == "3") {
                            $('#WeekendOTNight').val(OTLateNight + OTLateNightNextDay);
                            //dxGrid.SetEditValue('WeekendOTNight', OTLateNight + OTLateNightNextDay);
                        }
                        else if (jsonData.CalendarType == "2" || jsonData.CalendarType == "4") {
                            $('#WeekendOTNight').val(jsonData.OTLateNightNextDay);
                            //dxGrid.SetEditValue('WeekendOTNight', jsonData.OTLateNightNextDay);
                        }

                    }
                    else if (jsonData.CalendarTypeOfNextDay == "2" || jsonData.CalendarTypeOfNextDay == "4") {
                        if (jsonData.CalendarType == "1") {
                            $('#NaHolidayOTNight').val(jsonData.OTLateNightNextDay);
                            //dxGrid.SetEditValue('NaHolidayOTNight', jsonData.OTLateNightNextDay);
                        }
                        else if (jsonData.CalendarType == "3") {
                            $('#NaHolidayOTNight').val(jsonData.OTLateNightNextDay);
                            //dxGrid.SetEditValue('NaHolidayOTNight', jsonData.OTLateNightNextDay);
                        }
                        else if (jsonData.CalendarType == "2" || jsonData.CalendarType == "4") {
                            $('#NaHolidayOTNight').val(OTLateNight + OTLateNightNextDay);
                            //dxGrid.SetEditValue('NaHolidayOTNight', OTLateNight + OTLateNightNextDay);
                        }

                    }

                }

                //================================//

                var Code1 = $('#Code1').val();
                //Neu code1=Leave=> Khong auto
                if (Code1 != "11" && Code1 != "12" && Code1 != "13" && Code1 != "14") {
                    var _TotalWorkingTime = parseFloatCustom(jsonData.TotalWorkingTime);

                    var Hrs1 = parseFloatCustom($('#Hrs1').val());
                    var Hrs2 = parseFloatCustom($('#Hrs2').val());
                    var Hrs3 = parseFloatCustom($('#Hrs3').val());

                    var Hrs1Temp = _TotalWorkingTime - (Hrs2 + Hrs3);
                    if (Hrs1Temp <= 0) {
                        //Show messagebox
                        alert("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .");
                        //ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);

                        $('#Hrs1').val(jsonData.TotalWorkingTime);
                        //Reset value of Hrs2,Hrs3
                        $('#Hrs2').val(0);
                        $('#Hrs3').val(0);

                        // Set value for TotalWorkingHrs
                        $('#TotalWorkingHrs').val(jsonData.TotalWorkingTime);
                        s.focus();
                    }
                    else {
                        //Set value for Hrs1
                        $('#Hrs1').val(Hrs1Temp);
                        //Set value for TotalWorkingHrs
                        $('#TotalWorkingHrs').val(_TotalWorkingTime);

                    }

                    // Set value for TotalWorkingHrs

                    $('#TotalWorkingHrs').val(jsonData.TotalWorkingTime);
                }
                //RealOT
                //var TotalWorkingHrs = parseFloatCustom(jsonData.TotalWorkingTime);
                var Hrs1Value = parseFloatCustom($('#Hrs1').val());
                var Hrs2Value = parseFloatCustom($('#Hrs2').val());
                var Hrs3Value = parseFloatCustom($('#Hrs3').val());
                var TotalWorkingHrs = Hrs1Value + Hrs2Value + Hrs3Value;
                //Set value for TotalWorkingHrs
                $('#TotalWorkingHrs').val(TotalWorkingHrs);

                var MovingHrs = parseFloatCustom($('#MovingHrs').val());
                var RealOT = 0;

                if (jsonData.CalendarType == "1") {

                    var _TotalWorkingTimeInShift = parseFloatCustom(jsonData.OTShift); //OTShift=> Thoi gian lam viec trong gio ca

                    RealOT = TotalWorkingHrs - MovingHrs - _TotalWorkingTimeInShift;
                }
                else {
                    RealOT = TotalWorkingHrs - MovingHrs;
                }
                //Validate If RealOT<0
                if (RealOT < 0) {
                    //Show message
                    //                    showWarningWithoutCallBack(wMedium, "RealOT must be greater than 0.");
                    //Set default value and focus on field
                    //s.SetFocus();
                    $('#RealOT').val(0);
                }
                else {
                    $('#RealOT').val(RealOT);
                }
                //-End RealOT-


            }
        }
    });

    //_________________________________________________________________________________________
}
function SetDefaultStartFinish() {
    //Set value for Start and Finish
    $('#StartTime').val(HH_mm_tt);
    $('#FinishTime').val(HH_mm_tt);
}
//-----------------------------------//
// CallBack function
// 
//-----------------------------------//
function DefaultCallBack() { }

//-----------------------------------//
// Parse TimeSpan
// InPut Time Span Value: HH:mm tt=> return HH:mm:ss
//-----------------------------------//
function parseTimeSpan(value) {

    var d1 = new Date(new Date().toDateString() + " " + value);
    var HH = d1.getHours();
    if (HH < 10) { HH = '0' + HH; }
    var MM = d1.getMinutes();
    if (MM < 10) { MM = '0' + MM; }
    var ss = d1.getSeconds();
    if (ss < 10) { ss = '0' + ss; }
    var timeSpan = HH + ":" + MM + ":" + ss;
    return timeSpan;

}

//-----------------------------------//
// MessageBox-Show confirmation - without callback
//-----------------------------------//
function ShowDialogBox(message, button, callback) {
    //    $("#sure .sure-1").text(text1);
    $("#sure .sure-2").text(message);
    $("#sure .sure-do").text(button).on("click.sure", function () {
        callback();
        $(this).off("click.sure");
    });
    $.mobile.changePage("#sure");
}
//-----------------------------------------//
//    Hrs1ValueChanged
//----------------------------------------//


function OnHrs1ValueChanged(s, e) {

    //Calculate Time from TS
    var HrsFirstValue = s.value;
    var hrs1Value = $('#Hrs1').val();
    var hrs2Value = $('#Hrs2').val();
    var hrs3Value = $('#Hrs3').val();
    var Hrs1 = parseFloatCustom(hrs1Value);
    var Hrs2 = parseFloat(hrs2Value);
    var Hrs3 = parseFloat(hrs3Value);

    var TotalWorkingHrs = Hrs1 + Hrs2 + Hrs3;

    //Get In/Out Values
    var _Id = $('#Id').val();
    var startValue = $('#StartTime').val();

    var finishValue = $('#FinishTime').val();

    var _Start = parseTimeSpan(startValue);

    var _Finish = parseTimeSpan(finishValue);

    //Get NextDay
    var _NextDay = $('#NextDay').prop('checked'); //ouput: true||false

//    if (_Start == HH_mm_ss && _Finish == HH_mm_ss && _NextDay == true) {
//        var _TotalWorkingTime = 0;
//        //if TotalWorkingHrs > WorkingTime=> //alert()
//        if (TotalWorkingHrs > _TotalWorkingTime) {
//            //alert('TotalWorkingHrs > _TotalWorkingTime' + TotalWorkingHrs + " >" + _TotalWorkingTime);
//            //Show messagebox
//            ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);
//            //Set default value and focus on field
//            //Get Name of obj
//            ////alert(obj.getAttribute("name"));
//            //Set Value for obj
//            //s.value = 0;
//            s.focus();
//        }
//    }


    //Call Ajax to controller
    $.ajax({
        url: '/' + controller + '/CalculatingWorkingTime?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
        type: "GET",
        dataType: 'json',
        contentType: 'application/json;',
        data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
        success: function (jsonData) {

            if (jsonData.TotalWorkingTime != null) {
                var _TotalWorkingTime = parseFloatCustom(jsonData.TotalWorkingTime);
                if (TotalWorkingHrs > _TotalWorkingTime) {

                    //Show messagebox
                    alert("TotalWorkingHours cannot be greater than TotalWorkingTime= " + jsonData.TotalWorkingTime + " .");
                    //ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + jsonData.TotalWorkingTime + " .", 'OK', DefaultCallBack);
                    //Set default value and focus on field
                    s.value = _TotalWorkingTime;
                    $('#Hrs2').val(0);
                    $('#Hrs3').val(0);
                    // Set value for TotalWorkingHrs
                    $('#TotalWorkingHrs').val(_TotalWorkingTime);
                    s.focus();
                }
                else {

                    $('#TotalWorkingHrs').val(TotalWorkingHrs);

                    //Tính RealOT
                    var DateType = $('#DateType').val();
                    var movingHrsValue = $('#MovingHrs').val();
                    var MovingHrs = 0;

                    //If DateType= WorkDay else WeekendDay, Holiday, Festival
                    if (DateType == "1") {

                        // Call Ajax to controller
                        $.ajax({
                            url: '/' + controller + '/CalculatingWorkingTimeInShift?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
                            type: "GET",
                            dataType: 'json',
                            contentType: 'application/json;',
                            data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
                            success: function (jsonData) {
                                if (jsonData.TotalWorkingTimeInShift != null) {
                                    var _TotalWorkingTimeInShift = parseFloatCustom(jsonData.TotalWorkingTimeInShift);
                                    RealOT = TotalWorkingHrs - MovingHrs - _TotalWorkingTimeInShift;
                                }
                            }
                        });
                    }
                    else {
                        RealOT = TotalWorkingHrs - MovingHrs;
                        //Validate If RealOT<0
                        if (RealOT < 0) {
                            $('#RealOT').val(0);
                            //return;
                            //Show message
                            //showWarningWithoutCallBack(wMedium, "RealOT must be greater than 0.");
                            //Set default value and focus on field
                            //s.SetValue(0);
                            //s.SetFocus();
                        }
                        else {
                            $('#RealOT').val(RealOT);
                        }
                    }

                }
            }

        }
    });

}


//-----------------------------------------//
//    Hrs2ValueChanged
//----------------------------------------//
function OnHrs2ValueChanged(s, e) {

    //Calculate Time from TS
    var HrsFirstValue = s.value;
    var hrs1Value = $('#Hrs1').val();
    var hrs2Value = $('#Hrs2').val();
    var hrs3Value = $('#Hrs3').val();
    var Hrs1 = parseFloatCustom(hrs1Value);
    var Hrs2 = parseFloat(hrs2Value);
    var Hrs3 = parseFloat(hrs3Value);

    var TotalWorkingHrs = Hrs1 + Hrs2 + Hrs3;

    //Get In/Out Values
    var _Id = $('#Id').val();
    var startValue = $('#StartTime').val();

    var finishValue = $('#FinishTime').val();

    var _Start = parseTimeSpan(startValue);

    var _Finish = parseTimeSpan(finishValue);
    //Get NextDay
    var _NextDay = $('#NextDay').prop('checked'); //ouput: true||false

//    if (_Start == HH_mm_ss && _Finish == HH_mm_ss && _NextDay == true) {
//        var _TotalWorkingTime = 0;
//        //if TotalWorkingHrs > WorkingTime=> //alert()
//        if (TotalWorkingHrs > _TotalWorkingTime) {
//            //alert('TotalWorkingHrs > _TotalWorkingTime' + TotalWorkingHrs + " >" + _TotalWorkingTime);
//            //Show messagebox
//            ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);
//            //Set default value and focus on field
//            //Get Name of obj
//            ////alert(obj.getAttribute("name"));
//            //Set Value for obj
//            s.value = 0;
//            s.focus();
//        }
//    }

    var Code1 = $('#Code1').val();
    //Neu code1=Leave=> Khong auto
    if (Code1 != "11" && Code1 != "12" && Code1 != "13" && Code1 != "14") {
        //Call Ajax to controller
        $.ajax({
            url: '/' + controller + '/CalculatingWorkingTime?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
            type: "GET",
            dataType: 'json',
            contentType: 'application/json;',
            data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
            success: function (jsonData) {

                if (jsonData.TotalWorkingTime != null) {
                    var _TotalWorkingTime = parseFloatCustom(jsonData.TotalWorkingTime);
                    var Hrs1Temp = _TotalWorkingTime - (Hrs2 + Hrs3);
                    if (Hrs1Temp <= 0) {
                        //Show messagebox
                        alert("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .");
                        //ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);
                        //Set default value and focus on field
                        var sugestValue = _TotalWorkingTime - (Hrs1 + Hrs3);
                        if (sugestValue >= 0) {
                            $('#Hrs2').val(sugestValue);
                        }
                        s.focus();
                    }
                    else {
                        //Set value for Hrs1
                        $('#Hrs1').val(Hrs1Temp);

                        //Set value for TotalWorkingHrs
                        $('#TotalWorkingHrs').val(_TotalWorkingTime);
                    }
                }

            }
        });
    }
    else {
        //Tinh reaLOT
        $.ajax({
            url: '/' + controller + '/CalculatingOT?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
            type: "GET",
            dataType: 'json',
            contentType: 'application/json;',
            data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
            success: function (jsonData) {
                if (jsonData != null) {
                    //RealOT
                    //var TotalWorkingHrs = parseFloatCustom(jsonData.TotalWorkingTime);
                    var Hrs1Value = parseFloatCustom($('#Hrs1').val());
                    var Hrs2Value = parseFloatCustom($('#Hrs2').val());
                    var Hrs3Value = parseFloatCustom($('#Hrs3').val());
                    var TotalWorkingHrs = Hrs1Value + Hrs2Value + Hrs3Value;
                    //alert(TotalWorkingHrs);
                    //Set value for TotalWorkingHrs
                    $('#TotalWorkingHrs').val(TotalWorkingHrs);
                    var MovingHrs = parseFloatCustom($('#MovingHrs').val());
                    var RealOT = 0;

                    if (jsonData.CalendarType == "1") {

                        var _TotalWorkingTimeInShift = parseFloatCustom(jsonData.OTShift); //OTShift=> Thoi gian lam viec trong gio ca

                        RealOT = TotalWorkingHrs - MovingHrs - _TotalWorkingTimeInShift;
                    }
                    else {
                        RealOT = TotalWorkingHrs - MovingHrs;
                    }
                    //Validate If RealOT<0
                    if (RealOT < 0) {
                        //Show message
                        //                    showWarningWithoutCallBack(wMedium, "RealOT must be greater than 0.");
                        //Set default value and focus on field
                        //s.SetFocus();
                        $('#RealOT').val(0);
                    }
                    else {
                        $('#RealOT').val(RealOT);
                    }
                    //-End RealOT-


                }
            }
        });

    }


}
//-----------------------------------------//
//    Hr3ValueChanged
//----------------------------------------//
function OnHrs3ValueChanged(s, e) {

    //Calculate Time from TS
    var HrsFirstValue = s.value;
    var hrs1Value = $('#Hrs1').val();
    var hrs2Value = $('#Hrs2').val();
    var hrs3Value = $('#Hrs3').val();
    var Hrs1 = parseFloatCustom(hrs1Value);
    var Hrs2 = parseFloat(hrs2Value);
    var Hrs3 = parseFloat(hrs3Value);

    var TotalWorkingHrs = Hrs1 + Hrs2 + Hrs3;

    //Get In/Out Values
    var _Id = $('#Id').val();
    var startValue = $('#StartTime').val();

    var finishValue = $('#FinishTime').val();

    var _Start = parseTimeSpan(startValue);

    var _Finish = parseTimeSpan(finishValue);
    //Get NextDay
    var _NextDay = $('#NextDay').prop('checked'); //ouput: true||false

//    if (_Start == HH_mm_ss && _Finish == HH_mm_ss && _NextDay == true) {
//        var _TotalWorkingTime = 0;
//        //if TotalWorkingHrs > WorkingTime=> //alert()
//        if (TotalWorkingHrs > _TotalWorkingTime) {
//            //alert('TotalWorkingHrs > _TotalWorkingTime' + TotalWorkingHrs + " >" + _TotalWorkingTime);
//            //Show messagebox
//            ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);
//            //Set default value and focus on field
//            //Get Name of obj
//            ////alert(obj.getAttribute("name"));
//            //Set Value for obj
//            s.value = 0;
//            s.focus();
//        }
//    }

    var Code1 = $('#Code1').val();
    //Neu code1=Leave=> Khong auto
    if (Code1 != "11" && Code1 != "12" && Code1 != "13" && Code1 != "14") {
        //Call Ajax to controller
        $.ajax({
            url: '/' + controller + '/CalculatingWorkingTime?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish,
            type: "GET",
            dataType: 'json',
            contentType: 'application/json;',
            data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
            success: function (jsonData) {

                if (jsonData.TotalWorkingTime != null) {
                    var _TotalWorkingTime = parseFloatCustom(jsonData.TotalWorkingTime);
                    var Hrs1Temp = _TotalWorkingTime - (Hrs2 + Hrs3);
                    if (Hrs1Temp <= 0) {
                        //Show messagebox
                        alert("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .");
                        //ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);
                        //Set default value and focus on field
                        var sugestValue = _TotalWorkingTime - (Hrs1 + Hrs2);
                        if (sugestValue >= 0) {
                            $('#Hrs3').val(sugestValue);
                        }
                        s.focus();
                    }
                    else {
                        //Set value for Hrs1
                        $('#Hrs1').val(Hrs1Temp);

                        //Set value for TotalWorkingHrs
                        $('#TotalWorkingHrs').val(_TotalWorkingTime);
                    }
                }

            }
        });
    }
    else {
        //Tinh reaLOT
        $.ajax({
            url: '/' + controller + '/CalculatingOT?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
            type: "GET",
            dataType: 'json',
            contentType: 'application/json;',
            data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
            success: function (jsonData) {
                if (jsonData != null) {
                    //RealOT
                    //var TotalWorkingHrs = parseFloatCustom(jsonData.TotalWorkingTime);
                    var Hrs1Value = parseFloatCustom($('#Hrs1').val());
                    var Hrs2Value = parseFloatCustom($('#Hrs2').val());
                    var Hrs3Value = parseFloatCustom($('#Hrs3').val());
                    var TotalWorkingHrs = Hrs1Value + Hrs2Value + Hrs3Value;
                    //Set value for TotalWorkingHrs
                    $('#TotalWorkingHrs').val(TotalWorkingHrs);
                    var MovingHrs = parseFloatCustom($('#MovingHrs').val());
                    var RealOT = 0;

                    if (jsonData.CalendarType == "1") {

                        var _TotalWorkingTimeInShift = parseFloatCustom(jsonData.OTShift); //OTShift=> Thoi gian lam viec trong gio ca

                        RealOT = TotalWorkingHrs - MovingHrs - _TotalWorkingTimeInShift;
                    }
                    else {
                        RealOT = TotalWorkingHrs - MovingHrs;
                    }
                    //Validate If RealOT<0
                    if (RealOT < 0) {
                        //Show message
                        //                    showWarningWithoutCallBack(wMedium, "RealOT must be greater than 0.");
                        //Set default value and focus on field
                        //s.SetFocus();
                        $('#RealOT').val(0);
                    }
                    else {
                        $('#RealOT').val(RealOT);
                    }
                    //-End RealOT-

                }
            }
        });

    }
}

//-------------------------------
//
//-------------------------------
function DefaultCallBack() {
    //Do nothing
}

//-----------------------------------------//
// OnMovingHrsChanged
//----------------------------------------//
function OnMovingHrsChanged(s) {
    //alert('OnMovingHrsChanged');
    var MovingHrsFirstValue = $('#MovingHrs').val(); ;
    var DateType = $('#DateType').val();
    //alert('DateType = '+DateType);
    var TotalWorkingHrs = parseFloatCustom($('#TotalWorkingHrs').val());
    var MovingHrs = parseFloatCustom($('#MovingHrs').val());
    var RealOT = 0;

    //If DateType= WorkDay else WeekendDay, Holiday, Festival
    if (DateType == '1') {
        var _Id = $('#Id').val();
        var startValue = $('#StartTime').val();
        var finishValue = $('#FinishTime').val();
        var _Start = parseTimeSpan(startValue);
        var _Finish = parseTimeSpan(finishValue);
        //Get NextDay
        var _NextDay = $('#NextDay').prop('checked'); //ouput: true||false

        // Call Ajax to controller
        $.ajax({
            url: '/' + controller + '/CalculatingWorkingTimeInShift?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
            type: "GET",
            dataType: 'json',
            contentType: 'application/json;',
            data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
            success: function (jsonData) {

                if (jsonData.TotalWorkingTimeInShift != null) {
                    var totalWT = parseFloatCustom(jsonData.TotalWorkingTimeInShift);
                    var floatRealOT = TotalWorkingHrs - MovingHrs - totalWT;

                    if (floatRealOT < 0) {
                        //Show message 
                        // ShowDialogBox("RealOT must be greater than 0.", 'OK', DefaultCallBack);

                        //Set Value for obj
                        //s.value = 0;
                        // s.focus();
                        $('#RealOT').val(0);
                    }
                    else {
                        $('#RealOT').val(floatRealOT);
                    }


                }
            }
        });

    }
    else {
        RealOT = TotalWorkingHrs - MovingHrs;
        //Validate If RealOT<0
        if (RealOT < 0) {
            //Show message
            //showWarningWithoutCallBack(wMedium, "RealOT must be greater than 0.");
            //Set default value and focus on field
            //s.SetValue(0);
            //s.SetFocus();
            $('#RealOT').val(0);
        }
        else {
            $('#RealOT').val(RealOT);
        }
    }

}


//------------------------------//
//      OnOverTimeChanged       //
//------------------------------//
function OnOverTimeChanged(s) {
    //alert('OnOverTimeChanged');
    //1. Get OverTime Value
    var otBeforeAfterValue = $('#OTBeforeAfter').val();
    var OTBeforeAfter = 0;
    if (otBeforeAfterValue != null && otBeforeAfterValue != "") {
        OTBeforeAfter = parseFloat(otBeforeAfterValue);
    }

    var otLateNightValue = $('#OTLateNight').val();
    var OTLateNight = 0;
    if (otLateNightValue != null && otLateNightValue != "") {
        OTLateNight = parseFloat(otLateNightValue);
    }
    var weekendShiftValue = $('#WeekendShift').val();
    var WeekendShift = 0;
    if (weekendShiftValue != null && weekendShiftValue != "") {
        WeekendShift = parseFloat(weekendShiftValue);
    }

    var weekendOTValue = $('#WeekendOT').val();
    var WeekendOT = 0;
    if (weekendOTValue != null && weekendOTValue != "") {
        WeekendOT = parseFloat(weekendOTValue);
    }

    var weekendOTNightValue = $('#WeekendOTNight').val();
    var WeekendOTNight = 0;
    if (weekendOTNightValue != null && weekendOTNightValue != "") {
        WeekendOTNight = parseFloat(weekendOTNightValue);
    }
    var naHolidayShiftValue = $('#NaHolidayShift').val();
    var NaHolidayShift = 0;
    if (naHolidayShiftValue != null && naHolidayShiftValue != "") {
        NaHolidayShift = parseFloat(naHolidayShiftValue);
    }

    var naHolidayOTValue = $('#NaHolidayOT').val();
    var NaHolidayOT = 0;
    if (naHolidayOTValue != null && naHolidayOTValue != "") {
        NaHolidayOT = parseFloat(naHolidayOTValue);
    }
    var naHolidayOTNight = $('#NaHolidayOTNight').val();
    var NaHolidayOTNight = 0;
    if (naHolidayOTNight != null && naHolidayOTNight != "") {
        NaHolNaHolidayOTNightidayOT = parseFloat(naHolidayOTNight);
    }

    //2. Get RealOT Value
    var RealOT = parseFloatCustom($('#RealOT').val());
    var MovingHrs = parseFloatCustom($('#MovingHrs').val());
    var OverTime = OTBeforeAfter + OTLateNight + WeekendShift + WeekendOT + WeekendOTNight + NaHolidayShift + NaHolidayShift + NaHolidayOT + NaHolidayOTNight;
    //4. Check Validation: Sum(OverTime) <= (Real OT + Moving Hrs)
    if (OverTime > (RealOT + MovingHrs)) {
        //Show message
        alert("Total OverTime Hours cannot be greater than (Real OT + Moving Hrs)");
        //ShowDialogBox("Total OverTime Hours cannot be greater than (Real OT + Moving Hrs)", 'OK', DefaultCallBack);
        //Set default value and focus on field
        s.value = 0;
        s.focus();
    }
}


//------------------------------//
//      parseFloatCustom       //
//------------------------------//
function parseFloatCustom(floatInput) {
    var returnValue = 0;
    if (floatInput != null && floatInput != "") {
        returnValue = parseFloat(floatInput);
    }
    return returnValue;
}


//------------------------------//
//      OnCodeValueChanged      //
//------------------------------//
function OnCodeValueChanged(s) {


    //8. Khi nhân viên hết phép => Chọn code=Annual Leave
    //=> Xuất thông báo "đã hết phép" và không được chọn code= annual Leave
    //1. Get Code Value
    var Code = s.value;
    //Enable
    if (Code != "11" && Code != "12" && Code != "13" && Code != "14") {
        enableSelectCodeAndLeave();
    }

    //2. Check If code=AnualLeave(11)=> Check LeaveRemain
    if (Code == "11") {

        //Get Leave Remain
        var LeaveRemain = parseFloatCustom($('#LeaveRemain').val());
        if (LeaveRemain <= 0) {
            alert("LeveRemain is not enough. LeaveRemain=  " + LeaveRemain.toString());
            //ShowDialogBox("LeveRemain is not enough. LeaveRemain=  " + LeaveRemain.toString(), DefaultCallBack);
            s.value = "";
            s.focus();
            return;
        }
    }


    // Khi code=Leave=> Tại detail đó, các trường còn tại disible và value=null
    //2. Check Value if It's Leave or not
    if (Code == "11" || Code == "12" || Code == "13" || Code == "14") {

        //2.1 Check if (s) is Code1, Code2 or Code3 => return default values for other fields in Detail
        //Get object
        if ($('#Code1').attr('name') == $(s).attr('name')) {

            //Set Value for other fields in Detail  1 and Status=ReadOnly
            $('#RelatedJobNo1').val("");
            $('#RelatedJobNo1').selectmenu("refresh", true);
            $('#RelatedJobNo1').attr('readonly', true);
            $('#Hrs1').val(0);
            $('#Hrs1').attr('readonly', true);
        }
        else if ($('#Code2').attr('name') == $(s).attr('name')) {
            //Set Value for other fields in Detail 2
            $('#RelatedJobNo2').val("");
            $('#RelatedJobNo2').selectmenu("refresh", true);
            $('#RelatedJobNo2').attr('readonly', true);
            $('#Hrs2').val(0);
            $('#Hrs2').attr('readonly', true);
        }
        else if ($('#Code3').attr('name') == $(s).attr('name')) {
            //Set Value for other fields in Detail 3
            $('#RelatedJobNo3').val("");
            $('#RelatedJobNo3   ').selectmenu("refresh", true);
            $('#RelatedJobNo3').attr('readonly', true);
            $('#Hrs3').val(0);
            $('#Hrs3').attr('readonly', true);
        }
        //	9. Khi chọn code=Leave=> Focus on field [LeaveNo]. 
        //1. Get Editor By column
        $('#LeaveNo').focus();
        //______________________________________________________________________
        var _Id = $('#Id').val();
        var startValue = $('#StartTime').val();
        var finishValue = $('#FinishTime').val();
        var _Start = parseTimeSpan(startValue);
        var _Finish = parseTimeSpan(finishValue);
        //Get NextDay
        var _NextDay = $('#NextDay').prop('checked'); //ouput: true||false

        //Tinh reaLOT
        $.ajax({
            url: '/' + controller + '/CalculatingOT?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
            type: "GET",
            dataType: 'json',
            contentType: 'application/json;',
            data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish }),
            success: function (jsonData) {
                if (jsonData != null) {
                    //RealOT
                    //var TotalWorkingHrs = parseFloatCustom(jsonData.TotalWorkingTime);
                    var Hrs1Value = parseFloatCustom($('#Hrs1').val());
                    var Hrs2Value = parseFloatCustom($('#Hrs2').val());
                    var Hrs3Value = parseFloatCustom($('#Hrs3').val());
                    var TotalWorkingHrs = Hrs1Value + Hrs2Value + Hrs3Value;
                    //Set value for TotalWorkingHrs
                    $('#TotalWorkingHrs').val(TotalWorkingHrs);
                    var MovingHrs = parseFloatCustom($('#MovingHrs').val());
                    var RealOT = 0;

                    if (jsonData.CalendarType == "1") {

                        var _TotalWorkingTimeInShift = parseFloatCustom(jsonData.OTShift); //OTShift=> Thoi gian lam viec trong gio ca

                        RealOT = TotalWorkingHrs - MovingHrs - _TotalWorkingTimeInShift;
                    }
                    else {
                        RealOT = TotalWorkingHrs - MovingHrs;
                    }
                    //Validate If RealOT<0
                    if (RealOT < 0) {
                        //Show message
                        //                    showWarningWithoutCallBack(wMedium, "RealOT must be greater than 0.");
                        //Set default value and focus on field
                        //s.SetFocus();
                        $('#RealOT').val(0);
                    }
                    else {
                        $('#RealOT').val(RealOT);
                    }
                    //-End RealOT-

                }
            }
        });
        //______________________________________________________________________
    }
    else {
        //Get object
        if ($('#Code1').attr('name') == $(s).attr('name')) {
            //Set Value for other fields in Detail 1 and Status=ReadOnly
            $('#RelatedJobNo1').attr('readonly', false);
            $('#Hrs1').attr('readonly', false);
            //Begin__________________________________________________________________
            //Tinh lai thoi gian
            var _Id = $('#Id').val();
            var startValue = $('#StartTime').val();
            var finishValue = $('#FinishTime').val();
            var _Start = parseTimeSpan(startValue);
            var _Finish = parseTimeSpan(finishValue);
            //Get NextDay
            var _NextDay = $('#NextDay').prop('checked'); //ouput: true||false

            if (_Start == HH_mm_ss && _Finish == HH_mm_ss && _NextDay == true) {
                var _TotalWorkingTime = 0;
                //if TotalWorkingHrs > WorkingTime=> //alert()
                if (TotalWorkingHrs > _TotalWorkingTime) {
                    //alert('TotalWorkingHrs > _TotalWorkingTime' + TotalWorkingHrs + " >" + _TotalWorkingTime);
                    //Show messagebox
                    alert("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .");
                    //ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);
                    //Set default value and focus on field
                    //Get Name of obj
                    ////alert(obj.getAttribute("name"));
                    //Set Value for obj
                    //s.value = 0;
                    s.focus();
                }
            }
            //=====================================================================
            $.ajax({
                url: '/' + controller + '/CalculatingOT?id=' + _Id + '&start=' + _Start + '&finish=' + _Finish + '&isnextday=' + _NextDay,
                type: "GET",
                dataType: 'json',
                contentType: 'application/json;',
                data: JSON.stringify({ id: _Id, start: _Start, finish: _Finish, isnextday: _NextDay }),
                success: function (jsonData) {
                    if (jsonData != null) {
                        //================================//

                        var _TotalWorkingTime = parseFloatCustom(jsonData.TotalWorkingTime);

                        var Hrs1 = parseFloatCustom($('#Hrs1').val());
                        var Hrs2 = parseFloatCustom($('#Hrs2').val());
                        var Hrs3 = parseFloatCustom($('#Hrs3').val());

                        var Hrs1Temp = _TotalWorkingTime - (Hrs2 + Hrs3);
                        if (Hrs1Temp <= 0) {
                            //Show messagebox
                            alert("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .");
                            //ShowDialogBox("TotalWorkingHours cannot be greater than TotalWorkingTime= " + _TotalWorkingTime + " .", 'OK', DefaultCallBack);

                            $('#Hrs1').val(jsonData.TotalWorkingTime);
                            //Reset value of Hrs2,Hrs3
                            $('#Hrs2').val(0);
                            $('#Hrs3').val(0);

                            // Set value for TotalWorkingHrs
                            $('#TotalWorkingHrs').val(jsonData.TotalWorkingTime);
                            s.focus();
                        }
                        else {
                            //Set value for Hrs1
                            $('#Hrs1').val(Hrs1Temp);
                            //Set value for TotalWorkingHrs
                            $('#TotalWorkingHrs').val(_TotalWorkingTime);

                        }

                        // Set value for TotalWorkingHrs

                        $('#TotalWorkingHrs').val(jsonData.TotalWorkingTime);
                    }
                    //RealOT
                    //var TotalWorkingHrs = parseFloatCustom(jsonData.TotalWorkingTime);
                    var Hrs1Value = parseFloatCustom($('#Hrs1').val());
                    var Hrs2Value = parseFloatCustom($('#Hrs2').val());
                    var Hrs3Value = parseFloatCustom($('#Hrs3').val());
                    var TotalWorkingHrs = Hrs1Value + Hrs2Value + Hrs3Value;
                    //Set value for TotalWorkingHrs
                    $('#TotalWorkingHrs').val(TotalWorkingHrs);

                    var MovingHrs = parseFloatCustom($('#MovingHrs').val());
                    var RealOT = 0;

                    if (jsonData.CalendarType == "1") {

                        var _TotalWorkingTimeInShift = parseFloatCustom(jsonData.OTShift); //OTShift=> Thoi gian lam viec trong gio ca

                        RealOT = TotalWorkingHrs - MovingHrs - _TotalWorkingTimeInShift;
                    }
                    else {
                        RealOT = TotalWorkingHrs - MovingHrs;
                    }
                    //Validate If RealOT<0
                    if (RealOT < 0) {
                        //Show message
                        //                    showWarningWithoutCallBack(wMedium, "RealOT must be greater than 0.");
                        //Set default value and focus on field
                        //s.SetFocus();
                        $('#RealOT').val(0);
                    }
                    else {
                        $('#RealOT').val(RealOT);
                    }
                    //-End RealOT-
                }
            });
            //End__________________________________________________________________

        }
        else if ($('#Code2').attr('name') == $(s).attr('name')) {
            //Set Value for other fields in Detail 2
            $('#RelatedJobNo2').attr('readonly', false);
            $('#Hrs2').attr('readonly', false);
        }
        else if ($('#Code3').attr('name') == $(s).attr('name')) {
            //Set Value for other fields in Detail 3
            $('#RelatedJobNo3').attr('readonly', false);
            $('#Hrs3').attr('readonly', false);
        }

    }
}


//------------------------------//
//      OnLeaveNoValueChanged   //
//------------------------------//
function OnLeaveNoValueChanged(s) {

    //Get value object
    var Code1 = $('#Code1').val();
    var Code2 = $('#Code2').val();
    var Code3 = $('#Code3').val();
    //Nếu tồn tại code= Leave
    if ((Code1 == "11" || Code1 == "12" || Code1 == "13" || Code1 == "14"
    || Code2 == "11" || Code2 == "12" || Code2 == "13" || Code2 == "14"
    || Code3 == "11" || Code3 == "12" || Code3 == "13" || Code3 == "14") && s.value == "0") {
        ShowDialogBox("LeaveNo cannot be empty. Code1='" + Code1 + "', Code2='" + Code2 + "', Code3='" + Code3 + "'", DefaultCallBack);
        s.focus();
        return;
    }
    //Nếu [LeaveNo]=1 =>các trường còn lại reset về null
    //Set rest fields= default value, except field [Code#]
    if ($('#LeaveNo').val() == "1") {
        //If Code= Annual Leave(11) => Don't set default value
        if (Code1 == "11" || Code1 == "12" || Code1 == "13" || Code1 == "14") {
            $('#Start').val(HH_mm_tt);
            $('#Start').prop('disabled', true);
            $('#Finish').val(HH_mm_tt);
            $('#Finish').prop('disabled', true);
            //dxGrid.SetEditValue("Start", new Date(dxGrid.GetEditValue("Date")));
            //dxGrid.SetEditValue("Finish", new Date(dxGrid.GetEditValue("Date")));
            $('#RelatedJobNo1').val("");
            $('#RelatedJobNo1').selectmenu("refresh", true);
            $('#RelatedJobNo1').prop('disabled', true);
            $('#Hrs1').val(0);
            $('#Hrs1').prop('disabled', true);
            $('#RelatedJobNo2').val("");
            $('#RelatedJobNo2').selectmenu("refresh", true);
            $('#RelatedJobNo2').prop('disabled', true);
            $('#Code2').val("");
            $('#Code2').selectmenu("refresh", true);
            $('#Code2').prop('disabled', true);
            $('#Hrs2').val(0);
            $('#Hrs2').prop('disabled', true);
            $('#RelatedJobNo3').val("");
            $('#RelatedJobNo3').selectmenu("refresh", true);
            $('#RelatedJobNo3').prop('disabled', true);
            $('#Code3').val("");
            $('#Code3').selectmenu("refresh", true);
            $('#Code3').prop('disabled', true);
            $('#Hrs3').val(0);
            $('#Hrs3').prop('disabled', true);
            $('#MovingHrs').val(0);
            $('#TotalWorkingHrs').val(0);
            $('#WorkDay').val(0);
            $('#RealOT').val(0);
            $('#OTBeforeAfter').val(0);
            $('#OTLateNight').val(0);
            $('#WeekendShift').val(0);
            $('#WeekendOT').val(0);
            $('#WeekendOTNight').val(0);
            $('#NaHolidayShift').val(0);
            $('#NaHolidayOT').val(0);
            $('#NaHolidayOTNight').val(0);
        }
        if (Code2 == "11" || Code2 == "12" || Code2 == "13" || Code2 == "14") {
            $('#Start').val(HH_mm_tt);
            $('#Start').prop('disabled', true);
            $('#Finish').val(HH_mm_tt);
            $('#Finish').prop('disabled', true);
            //dxGrid.SetEditValue("Start", new Date(dxGrid.GetEditValue("Date")));
            //dxGrid.SetEditValue("Finish", new Date(dxGrid.GetEditValue("Date")));
            $('#RelatedJobNo1').val("");
            $('#RelatedJobNo1').selectmenu("refresh", true);
            $('#RelatedJobNo1').prop('disabled', true);
            $('#Code1').val("");
            $('#Code1').selectmenu("refresh", true);
            $('#Code1').prop('disabled', true);
            $('#Hrs1').val(0);
            $('#Hrs1').prop('disabled', true);
            $('#RelatedJobNo2').val("");
            $('#RelatedJobNo2').selectmenu("refresh", true);
            $('#RelatedJobNo2').prop('disabled', true);
            $('#Hrs2').val(0);
            $('#Hrs2').prop('disabled', true);
            $('#RelatedJobNo3').val("");
            $('#RelatedJobNo3').selectmenu("refresh", true);
            $('#RelatedJobNo3').prop('disabled', true);
            $('#Code3').val("");
            $('#Code3').selectmenu("refresh", true);
            $('#Code3').prop('disabled', true);
            $('#Hrs3').val(0);
            $('#Hrs3').prop('disabled', true);
            $('#MovingHrs').val(0);
            $('#TotalWorkingHrs').val(0);
            $('#WorkDay').val(0);
            $('#RealOT').val(0);
            $('#OTBeforeAfter').val(0);
            $('#OTLateNight').val(0);
            $('#WeekendShift').val(0);
            $('#WeekendOT').val(0);
            $('#WeekendOTNight').val(0);
            $('#NaHolidayShift').val(0);
            $('#NaHolidayOT').val(0);
            $('#NaHolidayOTNight').val(0);
        }
        if (Code3 == "11" || Code3 == "12" || Code3 == "13" || Code3 == "14") {
            $('#Start').val(HH_mm_tt);
            $('#Start').prop('disabled', true);
            $('#Finish').val(HH_mm_tt);
            $('#Finish').prop('disabled', true);
            //dxGrid.SetEditValue("Start", new Date(dxGrid.GetEditValue("Date")));
            //dxGrid.SetEditValue("Finish", new Date(dxGrid.GetEditValue("Date")));
            $('#RelatedJobNo1').val("");
            $('#RelatedJobNo1').selectmenu("refresh", true);
            $('#RelatedJobNo1').prop('disabled', true);
            $('#Code1').val("");
            $('#Code1').selectmenu("refresh", true);
            $('#Code1').prop('disabled', true); ;
            $('#Hrs1').val(0);
            $('#Hrs1').prop('disabled', true);
            $('#RelatedJobNo2').val("");
            $('#RelatedJobNo2').selectmenu("refresh", true);
            $('#RelatedJobNo2').prop('disabled', true);
            $('#Code2').val("");
            $('#Code2').selectmenu("refresh", true);
            $('#Code2').prop('disabled', true);
            $('#Hrs2').val(0);
            $('#Hrs2').prop('disabled', true);
            $('#RelatedJobNo3').val("");
            $('#RelatedJobNo3').selectmenu("refresh", true);
            $('#RelatedJobNo3').prop('disabled', true);
            //$('#Code3').val("");
            $('#Hrs3').val(0);
            $('#Hrs3').prop('disabled', true); ;
            $('#MovingHrs').val(0);
            $('#TotalWorkingHrs').val(0);
            $('#WorkDay').val(0);
            $('#RealOT').val(0);
            $('#OTBeforeAfter').val(0);
            $('#OTLateNight').val(0);
            $('#WeekendShift').val(0);
            $('#WeekendOT').val(0);
            $('#WeekendOTNight').val(0);
            $('#NaHolidayShift').val(0);
            $('#NaHolidayOT').val(0);
            $('#NaHolidayOTNight').val(0);
        }
    }
    else {
        $('#Start').prop('disabled', false);
        $('#Finish').prop('disabled', false);
        $('#RelatedJobNo1').prop('disabled', false);
        $('#Code1').prop('disabled', false);
        $('#Hrs1').prop('disabled', false);
        $('#RelatedJobNo2').prop('disabled', false);
        $('#Code2').prop('disabled', false);
        $('#Hrs2').prop('disabled', false);
        $('#RelatedJobNo3').prop('disabled', false);
        $('#StCode3rt').prop('disabled', false);
        $('#Hrs3').prop('disabled', false);
    }
}

function OnRelatedJobValueChanged(s, e) {

    if ($(s).is('[readonly]') == true) {
        $(s).val("");
        $(s).selectmenu("refresh", true);
    }
}

function enableSelectCodeAndLeave() {
    $('#Start').prop('disabled', false);
    $('#Finish').prop('disabled', false);
    $('#RelatedJobNo1').prop('disabled', false);
    $('#Code1').prop('disabled', false);
    $('#Hrs1').prop('disabled', false);
    $('#RelatedJobNo2').prop('disabled', false);
    $('#Code2').prop('disabled', false);
    $('#Hrs2').prop('disabled', false);
    $('#RelatedJobNo3').prop('disabled', false);
    $('#StCode3rt').prop('disabled', false);
    $('#Hrs3').prop('disabled', false);
}

function SubmitWorkReport() {

    ShowDialogBox("Are you sure that you want to submit?", "OK", Submit);

}

function Submit() {
    var _id = $('#Id').val();
    //Call Submit
    $.ajax({
        url: '/' + controller + '/Submit?id=' + _Id,
        type: "GET",
        dataType: 'json',
        contentType: 'application/json;',
        success: function (data) {
            return;
        }
    });
}

